$(function () {
    var arr = [];
    if (localStorage.getItem("historyArr")) {
        var arrList = JSON.parse(localStorage.getItem("historyArr"))
        console.log(arrList)
        var html = template("artlist", {
            result: arrList
        })
        // console.log(html)
        $(".lt_history").html(html)
    }
    $(".search_btn").on('tap', function () {
        var vals = $.trim($(".search_input").val())
        if (vals == "") {
            mui.toast("请输入关键字搜索")
            return;
        } else {
            arr = [].concat(arrList)
            console.log(arr)
            arr.push(vals)
            localStorage.setItem("historyArr", JSON.stringify(arr))
            location.href="searchList.html?key="+vals;
        }

    })
    $("body").on('tap', ".delSingle", function () {
        console.log($(this).attr("data-index"))
        var delId = $(this).attr("data-index")
        //    console.log(arrList)
        arrList.splice(delId, 1)
        localStorage.setItem("historyArr", JSON.stringify(arrList))
        location.reload()
    })
    $("body").on('tap', ".mui-icon-trash", function () {
        //方法一
        arrList.length = 0
        localStorage.setItem("historyArr", JSON.stringify(arrList))
        location.reload()
        // 方法二
        // localStorage.removeItem("historyArr")
        // location.reload()
        // $(".lt_history").empty()
    })







})